<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Music/classes/PhpFox_ComponentViewMusician.class.php, $Author:  $ */



/** Component for viewing musicians
 *   
 * @version $Id: PhpFox_ComponentViewMusician.class.php 367 2008-02-26 13:47:03Z phpfoxsv $
 * @package module.music
 */
class PhpFox_Mod_Music_ComponentViewMusician extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oMusicService = &$this->_oModule->getService('Music');
        /* @var $oMusicService PhpFox_Mod_Music_ServiceMusic */
        $oMusicianItem = &$this->_oModule->getItem('Musician');
        /* @var $oMusicianItem PhpFox_Mod_Music_ItemMusician */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = &$this->_oModule->getTemplate();
        $oCurrUser = $oSecurityService->getCurrentUser();

        $oSecurityService->checkPerm('music', array('read_only', 'full'));
        $oSecurityService->checkAccess('music');
        $iMusicianId = $oReq->getInt('id');
        $bStaff = $oSecurityService->isStaff();
        if (!$iMusicianId)
        {
            App::gotoUrl('public.music');
        }
        if (!$oMusicianItem->load($iMusicianId))
        {
            App::gotoUrl('public.music');
        }

        if ($iSongId = $oReq->getInt('fsong'))
        {
        	if(!$oCurrUser)
        		App::gotoUrl('public.login');
            if ($oMusicService->makeSongFavorite($iSongId))
            {
                App::gotoUrl('public.account.favorites');
            }
            App::gotoUrl();
        }

        if ($iAlbumId = $oReq->getInt('falbum'))
        {
        	if(!$oCurrUser)
        		App::gotoUrl('public.login');
            if ($oMusicService->makeAlbumFavorite($iAlbumId))
            {
                App::gotoUrl('public.account.favorites');
            }
            App::gotoUrl();
        }

        if ($iSongId = $oReq->getInt('makefeatured'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId);
            }
            App::gotoUrl('', array('id' => $iMusicianId));
        }
        if ($iSongId = $oReq->get('makeaccount'))
        {
            $oMusicService->setActualAccountMusic($iSongId);
            App::gotoUrl('', array('id' => $iMusicianId));
        }
        if ($iSongId = $oReq->getInt('deletefeatured'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId, false);
            }
            App::gotoUrl('', array('id' => $iMusicianId));
        }
        $aCond = array
        (
            'musician_id' => '= '.$iMusicianId,
        );
        list($aAlbums) = $oMusicService->getAlbumsList($aCond);
        foreach ($aAlbums as $iKey => $aAlbum)
        {
            $aAlbums[$iKey]['album_is_favorite'] = $oMusicService->isAlbumFavorite($aAlbum['album_id']);
        }
        list($aSongs) = $oMusicService->getSongsList($aCond, 0, 0, 'song_title');
        foreach ($aSongs as $iKey => $aSong)
        {
            $aSongs[$iKey]['song_is_favorite'] = $oMusicService->isSongFavorite($aSong['song_id']);
            $aSongs[$iKey]['song_is_actual'] = $oMusicService->isSongActual($aSong['song_id']);
            $aSongs[$iKey]['song_owner'] 	   = $aSong['user_id'] == $oCurrUser->aData['id'];
        }

        $oTpl->assign(array(
            'aAlbums'    => $aAlbums,
            'aMusician'  => $oMusicianItem->aData,
            'bStaff'     => $bStaff,
            'aSongs'     => $aSongs,
            'sAlbumsUrl' => App::getParam('music.album.pic.url'),
            'oCurrUser'  => $oSecurityService->getCurrentUser(),
        ));
        return $oTpl->fetch('ViewMusician.html');
    }
}
?>